<template>
<div style="padding: 1%">
  <div>
    <el-button @click="back" icon="el-icon-arrow-left" circle></el-button>
    
  </div>
  <el-form 
   :model="ruleForm"
   :rules="rules" 
   ref="ruleForm" 
   label-width="100px" 
   class="demo-ruleForm"
   >

  <el-form-item label="用例名称" prop="case_name" style="width:550px">
    <el-input v-model="ruleForm.case_name"></el-input>
  </el-form-item>

  <el-form-item label="标识" prop="test_id" style="width:550px">
    <el-input v-model="ruleForm.test_id"></el-input>
  </el-form-item>

  <el-form-item label="追踪关系" prop="pro_index" style="width:700px">
    <el-select v-model="ruleForm.pro_index" placeholder="请选择">
      <el-option
        v-for="item in getpro_index"
        :key="item.pro_index"
        :value="item.pro_index"
      >
      </el-option>
    </el-select>
  </el-form-item>

  <el-form-item label="前提约束" prop="qtys">
    <el-select v-model="ruleForm.qtys" placeholder="请选择版本号">
      <el-option label="V1.0" value="版本号：V1.0"></el-option>
      <el-option label="V2.0" value="版本号：V2.0"></el-option>
      <el-option label="V3.0" value="版本号：V3.0"></el-option>
      <el-option label="V4.0" value="版本号：V4.0"></el-option>
    </el-select>
  </el-form-item>

  <el-form-item label="设计方法" prop="sjff">
    <el-radio-group v-model="ruleForm.sjff">
      <el-radio label="等价类划分法"></el-radio>
      <el-radio label="边界值分析法"></el-radio>
      <el-radio label="场景法"></el-radio>
      <el-radio label="因果图"></el-radio>
      <el-radio label="决策表"></el-radio>
      <el-radio label="错误推测法"></el-radio>
    </el-radio-group>
  </el-form-item>

  <el-form-item label="输入及操作" prop="init">
    <el-input type="textarea" v-model="ruleForm.init"></el-input>
  </el-form-item>

  <el-form-item label="期望结果" prop="qwjg">
    <el-input type="textarea" v-model="ruleForm.qwjg"></el-input>
  </el-form-item>

  <el-form-item label="评估标准" prop="pgbz">
    <el-input type="textarea" v-model="ruleForm.pgbz"></el-input>
  </el-form-item>

  <el-form-item label="设计人员" prop="pro_members">
    <el-select v-model="ruleForm.pro_members" placeholder="请选择相应的测试工程师">
      <el-option label="admin" value="admin"></el-option>
      <el-option label="visit" value="visit"></el-option>
    </el-select>
  </el-form-item>

  <el-form-item label="所属功能节点" prop="label" style="width:700px">
    <el-select v-model="ruleForm.label" placeholder="请选择">
      <el-option
        v-for="item in pointList"
        :key="item.label"
        :value="item.label"
      >
      </el-option>
    </el-select>
  </el-form-item>

  <el-form-item label="设计时间" required>
    <el-col :span="11">
      <el-form-item prop="date1">
        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date1" style="width: 100%;"></el-date-picker>
      </el-form-item>
    </el-col>
    <el-col class="line" :span="2">-</el-col>
    <el-col :span="11">
      <el-form-item prop="date2">
        <el-time-picker placeholder="选择时间" v-model="ruleForm.date2" style="width: 100%;"></el-time-picker>
      </el-form-item>
    </el-col>
  </el-form-item>
  
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
    <el-button @click="back">取消</el-button>
  </el-form-item>

 </el-form>
</div>
</template>

<script>
  export default {
    data() {
      return {
        pointList: [],
        getpro_index: [],
        editForm: {},
        ruleForm: {
          case_name: '',
          test_id: '',
          pro_index: '',
          qtys: '',
          sjff: '',
          init: '',
          qwjg: '',
          pgbz: '',
          pro_members: '',
          label: '',
          date1: '',
          date2: ''
        },
        rules: {
          // name: [
          //   { required: true, message: '请输入活动名称', trigger: 'blur' },
          //   { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          // ],
          // region: [
          //   { required: true, message: '请选择活动区域', trigger: 'change' }
          // ],
          // date1: [
          //   { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
          // ],
          // date2: [
          //   { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
          // ],
          // type: [
          //   { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
          // ],
          // resource: [
          //   { required: true, message: '请选择活动资源', trigger: 'change' }
          // ],
          // desc: [
          //   { required: true, message: '请填写活动形式', trigger: 'blur' }
          // ]
        }
      };
    },
    mounted: function() {
      this.look()
    },

    mounted: function() {
      this.get_index()
      this.getpoint()
    },

    methods: {
      getpoint(){
        this.$http.get('/api/get_point').then(res=>{
          this.pointList = res.data
        });
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            
          this.$http.post('/api/test_case', this.ruleForm).then(res=>{
            console.log(res.data)
          });
            alert('submit!');
            this.$router.push('/cases/gongneng')
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      back(){
        this.$router.push('/cases/gongneng')
      },
      look(){
        this.$http.get('/api/test_case_edit').then(res=>{
          this.ruleForm = res.data[0]
          console.log(this.ruleForm)
        });
      },
      get_index(){
        this.$http.get('/api/test_case_index').then(res=>{
          this.getpro_index = res.data
        });
      }
    }
  }
</script>